
#include "game_controller\headers\game_controller_level_controller.hpp"

#include "game_controller\headers\game_controller_level.hpp"

#include "resource_controller\ih\resource_controller_object_describer.hpp"

#include <QtGui\qpixmap.h>

namespace GameController {


LevelController::LevelController( std::shared_ptr< GameModel::IObjectFactory > _gameModelFactory )
	:	m_objectCreator( _gameModelFactory )
{
}


LevelController::~LevelController()
{
}


std::shared_ptr< ILevel >
LevelController::getCurrentLevel() const
{
	return m_currentLevel;
}


void
LevelController::loadLevel( int _levelIdentificator )
{
	if( _levelIdentificator == 1 )
	{
		m_currentLevel.reset( new Level() );

		//TODO: This messed up code should be placed in resource controller.
		//After that, I think, we should remove linkage of QtGui lib to game controller plugin

		std::shared_ptr< ResourceController::ObjectDescriber > describer1( new ResourceController::ObjectDescriber( "object1" ) );
		describer1->setHorizontalSize( 3 );
		describer1->setVerticalSize( 5 );
		describer1->setStartHorizontalLocation( 2 );
		describer1->setStartVerticalLocation( 2 );
		QImage* pixmap1( new QImage( "..\\resources\\barrel_sprite.png" ) );
		describer1->setObjectPicture( pixmap1 );

		std::shared_ptr< ResourceController::ObjectDescriber > describer2( new ResourceController::ObjectDescriber( "object2" ) );
		describer2->setHorizontalSize( 3 );
		describer2->setVerticalSize( 5 );
		describer2->setStartHorizontalLocation( 7 );
		describer2->setStartVerticalLocation( 2 );
		QImage* pixmap2( new QImage( "..\\resources\\barrel_sprite.png" ) );
		describer2->setObjectPicture( pixmap2 );

		std::shared_ptr< ResourceController::ObjectDescriber > describer3( new ResourceController::ObjectDescriber( "object3" ) );
		describer3->setHorizontalSize( 3 );
		describer3->setVerticalSize( 5 );
		describer3->setStartHorizontalLocation( 12 );
		describer3->setStartVerticalLocation( 2 );
		QImage* pixmap3( new QImage( "..\\resources\\barrel_sprite.png" ) );
		describer3->setObjectPicture( pixmap3 );

		std::shared_ptr< ResourceController::ObjectDescriber > describer4( new ResourceController::ObjectDescriber( "object4" ) );
		describer4->setHorizontalSize( 3 );
		describer4->setVerticalSize( 5 );
		describer4->setStartHorizontalLocation( 17 );
		describer4->setStartVerticalLocation( 2 );
		QImage* pixmap4( new QImage( "..\\resources\\barrel_sprite.png" ) );
		describer4->setObjectPicture( pixmap4 );

		std::shared_ptr< ResourceController::ObjectDescriber > describer5( new ResourceController::ObjectDescriber( "object5" ) );
		describer5->setHorizontalSize( 3 );
		describer5->setVerticalSize( 5 );
		describer5->setStartHorizontalLocation( 22 );
		describer5->setStartVerticalLocation( 2 );
		QImage* pixmap5( new QImage( "..\\resources\\barrel_sprite.png" ) );
		describer5->setObjectPicture( pixmap5 );

		QImage* back( new QImage( "..\\resources\\background_with_alpha_cops.png" ) );

		getCurrentLevel()->addObject( m_objectCreator.createUnmovingObject( describer1 ) );
		getCurrentLevel()->addObject( m_objectCreator.createUnmovingObject( describer2 ) );
		getCurrentLevel()->addObject( m_objectCreator.createUnmovingObject( describer3 ) );
		getCurrentLevel()->addObject( m_objectCreator.createUnmovingObject( describer4 ) );
		getCurrentLevel()->addObject( m_objectCreator.createUnmovingObject( describer5 ) );
		getCurrentLevel()->setBackground( back );
	}
}


} // namespace GameController